#!/usr/bin/env bash

set -e

echo "---> Add Config"
cat > ./.dredd/config.json <<EOF
{
	"mysql": {
		"host": "${MYSQL_SERVICE}:${MYSQL_PORT}",
		"user": "semaphore",
		"pass": "semaphore",
		"name": "semaphore"
	}
}
EOF

echo "---> Waiting for semaphore"
while ! nc -z ${SEMAPHORE_SERVICE} ${SEMAPHORE_PORT}; do
  sleep 1
done

echo "---> Run Dredd"
# We do this because otherwise it can fail out
sleep 5
/home/developer/node_modules/.bin/dredd $@